package class001_010;

/**
 * ClassName: Code09_ListReverse
 * Package: class001_010
 * Description:
 *
 * @Author s
 * @Create 2025/7/24 15:59
 * @Version 1.0
 */
public class Code09_ListReverse {

    public static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode next = null;

        while(head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }

        return pre;
    }
}
